package tetrismain;

import java.util.ArrayList;

public abstract class Piece {
	public static final int I_ID = 1;
	public static final int J_ID = 2;
	public static final int L_ID = 3;
	public static final int O_ID = 4;
	public static final int S_ID = 5;
	public static final int T_ID = 6;
	public static final int Z_ID = 7;
	private ArrayList<Block> my_blocks;
	private int x;
	private int y;
	int rotation;

	public Piece() {
		my_blocks = new ArrayList<Block>();
		rotation = 0;
		buildPiece();
		x = 0;
		y = 0;
	}

	public int getRotationNumber() {
		return rotation;
	}

	public void incrementRotation() {
		if (rotation < 3) {
			rotation++;
		} else {
			rotation = 0;
		}
	}

	public void moveDown() {
		for (Block i : my_blocks) {
			i.setY(i.getY() + 1);
		}
		y++;
	}

	public void moveLeft() {
		for (Block i : my_blocks) {
			i.setX(i.getX() - 1);
		}
		x--;
	}

	public void moveRight() {
		for (Block i : my_blocks) {
			i.setX(i.getX() + 1);
		}
		x++;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public abstract void rotate();

	public abstract void buildPiece();

	public void setPiece(ArrayList<Block> the_blocks) {
		my_blocks.clear();
		for (Block i : the_blocks) {
			my_blocks.add(new Block(i.getX(), i.getY(), i.getId()));
		}
	}

	public ArrayList<Block> getPiece() {
		ArrayList<Block> copy = new ArrayList<Block>();
		for (Block i : my_blocks) {
			copy.add(new Block(i.getX(), i.getY(), i.getId()));
		}
		return copy;
	}

}
